import logging
import traceback
from functools import wraps

def log_decorator(func):
    logger = logging.getLogger(__name__)
    @wraps(func)
    def wrapper(*args, **kwargs):
        try:
            logger.info(f'{func.__name__}开始运行')
            # 执行原函数
            result = func(*args, **kwargs)
            logger.info(f'{func.__name__}运行结束')
            return result
        except Exception as e:
            # 获取当前执行的代码行信息
            tb = traceback.extract_stack(limit=2)
            line_info = tb[-2]
            logger.error(f'Error in {func.__name__} at line {line_info.lineno}: {e}')
            raise
    return wrapper
